<?php
protectScript('SourceEditorModel.php');

if(!defined('VERSION')){
	define('VERSION', '0.0');
	define('APP_TITLE', 'At Your Side');

	define('APP_USE_TYPE', 'dev');

	if(APP_USE_TYPE == 'dev'){
		define('WEBAPP_DIR', 'C:/xampp/htdocs/personal_website/ays');
		define('ROOT_URL', 'http://localhost/personal_website/ays');
		define('MODEL_DIR', WEBAPP_DIR . '/application/model');
		define('CONTROLLER_DIR', WEBAPP_DIR . '/application/controller');
		define('IMAGE_DIR', ROOT_URL . '/public/image');

		define('BASE_URL', '/personal_website/ays');

		define('BDD_HOST', 'localhost');
		define('BDD_USER', 'root');
		define('BDD_PASS', '');
		define('BDD_DATABASE', 'ays');
		define('TABLE_PREFIX', 'ays_');
	} elseif(APP_USE_TYPE == 'prod') {
		define('WEBAPP_DIR', '/var/www/vhosts/free-h.net/subdomains/ays/httpdocs/ays');
		define('ROOT_URL', 'http://ays.free-h.net/ays');
		define('MODEL_DIR', WEBAPP_DIR . '/application/model');
		define('CONTROLLER_DIR', WEBAPP_DIR . '/application/controller');
		define('IMAGE_DIR', ROOT_URL . '/public/image');

		define('BASE_URL', '/ays');

		define('BDD_HOST', 'sql1.free-h.org');
		define('BDD_USER', 'ren_sql48');
		define('BDD_PASS', 'f2fba1b6d7ab');
		define('BDD_DATABASE', 'freeh_ren');
		define('TABLE_PREFIX', 'ays_');
	}

}

class SourceEditorModel{
	private static $_asmWritableProps = array(
		'sCurrentDirectory' => '/'
	);

	public function __construct($asmEditorInfos = null){
		self::$_asmWritableProps['sCurrentDirectory'] =
			(isset($asmEditorInfos['sCurrentDirectory']))
			? $asmEditorInfos['sCurrentDirectory']
			: self::$_asmWritableProps['sCurrentDirectory']
		;
	}

	public static function listCurrentDirectory(){
		$rHandle = opendir(self::$_asmWritableProps['sCurrentDirectory']);

		$aiassFilesInfos = array();
		$aisDirectoryInfos = array();
		while(false !== ($rCurrentResource = readdir($rHandle))){
		  if(substr(strrchr($rCurrentResource, '.'), 1)){
				$sExtension = substr(strrchr($rCurrentResource, '.'), 1);

				$rCurrentFile = fopen($rCurrentResource, 'r');
				displayContentArray('Meta', stream_get_meta_data($rCurrentFile));

				$aiassFilesInfos[] = array(
					'sCompleteNameFile' => $rCurrentResource,
					'sExtensionFile' => $sExtension
				);
			}else{
				$aisDirectoryInfos[] = $rCurrentResource;
			}
		}

		closedir($rHandle);

		return $asaCurrentDirectoryContent = array(
			'aisDirectoryInfos' => $aisDirectoryInfos,
			'aiassFilesInfos' => $aiassFilesInfos
		);
	}
}